Repository navigation
refactor(chat): move ACP, endpoint, and provider leaves under loopx.chat and ratchet module budget (#5072) - #9196
loopx-agent wants to merge 1 commit into
Conversation
…hat and ratchet module budget Implements the next monorepo-distribution-split-v0 (#5072) M1 internal leaf migration batch without permanent top-level compatibility shims: - Move loopx/chat_acp.py -> loopx/chat/acp.py - Move loopx/chat_endpoints.py -> loopx/chat/endpoints.py - Move loopx/chat_providers.py -> loopx/chat/providers.py - Update internal relative imports, callers, tests, smokes, layout guards, and kiro_cli_goal_mode references - Ratchet tests/architecture/top_level_module_budget.json from 122 to 119 at baseline 00f47ed Signed-off-by: LoopX Agent <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
LoopX Chat 运行时(ChatRuntimeController、open_chat_session)、原生模型设置模块(model_settings)、CLI chat-endpoint 命令以及 loopx-core 与 loopx-workspace 分包维护者。
迁移前:loopx/chat_acp.py、loopx/chat_endpoints.py 与 loopx/chat_providers.py 三个仅服务于内部 Chat 传输与端点的模块仍扁平放置在 loopx/ 顶层,使 loopx/*.py 保持在 122 个并模糊包内归属边界;迁移后:三者直接通过 git mv 并入 loopx/chat/{acp,endpoints,providers}.py,同步更新全仓 25 个文件内的相对导入、测试与示例引用,删除顶层旧模块且不留兼容 shim,并将 top_level_module_budget.json 从 122 收紧至 119。
全仓 loopx/*.py 顶层模块数精确降为 119 且与 top_level_module_budget.json(119)一致;importlib.util.find_spec 对 loopx.chat_acp、loopx.chat_endpoints 与 loopx.chat_providers 均返回 None;跨模块导入、ACP/Claude/直连模型适配器行为、AgentEndpointRegistry 读写权限(0600)与 chat-endpoint list CLI 均与迁移前等价。
本 PR 不改动任何运行时会话语义、协议 schema、ACP/Provider 行为逻辑或 loopx.chat_action_store 边界,也不合并并行 PR #9179 的搬迁批次或修改远端分支保护策略。
loopx/ 顶层仍保留其余待迁出的 chat_*.py 与主机模式目录(例如 chat_action_store.py 受当前 loopx-core 边界测试约束留在后续批次),且主干已推进至 PR #9193 后本分支处于 BEHIND(无文件冲突)。
改动思路 / Approach
围绕仓库既定分包与减法规范(docs/architecture/rfcs/monorepo-distribution-split-v0.md @ 16f418837c87ab40f04ff303962598f5bd71a034),对 loopx/chat_acp.py、loopx/chat_endpoints.py 与 loopx/chat_providers.py 三个内部叶子模块执行“无兼容 shim 的直接迁入 + 全量调用点同步 + 单向预算棘轮”策略。由于原计划中的 chat_action_store.py 仍被 tests/control_plane/test_installed_core_context.py 与 packages/loopx-core/prepare.py 的核心分包边界断言显式引用,作者将其替换为与并行 PR #9179 无重叠的 chat_acp.py,避免了在搬迁 PR 中夹带跨分包契约变更。
将仅在内部使用的 ACP stdio 适配器、本地端点注册表和 Claude/直连模型适配器作为纯代码组织内移并入 loopx/chat/,既不新增适配层、注册表或运行时开关,又直接把顶层模块上限按净删减量从 122 压低至 119,是符合 M1 与 I3 的最小可逆边界。
当前 PR 边界(current_pr_boundary):当前 PR 仅搬迁 chat_acp、chat_endpoints、chat_providers 三枚非 loopx-core 约束叶子模块并更新全仓内部调用方与预算棘轮,故意把受 test_installed_core_context.py 边界断言约束的 chat_action_store.py 与其余叶子模块留待 #5072 后续独立批次。
搬迁前后导入流向对比:
迁移前: loopx/chat/{session_open,endpoint_catalog} / loopx/chat_runtime / model_settings / support_control_chat_endpoint
──▶ loopx.chat_acp / loopx.chat_endpoints / loopx.chat_providers (top-level 122)
迁移后: loopx/chat/{session_open} / loopx/chat_runtime / model_settings / support_control_chat_endpoint
──▶ loopx.chat.acp / loopx.chat.endpoints / loopx.chat.providers (top-level 119, 旧路径 find_spec=None)
具体改动 / Changes
依据规范 docs/architecture/rfcs/monorepo-distribution-split-v0.md(修订 16f418837c87ab40f04ff303962598f5bd71a034)逐条核对以下验收标准:
M1(implemented):通过git mv将loopx/chat_acp.py、loopx/chat_endpoints.py、loopx/chat_providers.py分别迁入loopx/chat/acp.py、loopx/chat/endpoints.py与loopx/chat/providers.py,由tests/test_chat_internal_module_layout.py校验新模块归属loopx.chat.*。I3(implemented):全仓不存在对这 3 个模块的对外公开重导出(loopx/__init__.py与loopx/chat.py均未暴露);PR 同步更新所有内部调用方、monkeypatch 字符串目标、3 个离线 smoke、1 个浏览器 smoke 脚本及kiro_cli_goal_mode文档注释,且不保留任何顶层兼容 shim。Section 9 row 1(implemented):tests/architecture/top_level_module_budget.json将max_top_level_modules从122精确下调 3 至119(实测ls -1 loopx/*.py | wc -l为119),tests/architecture/test_top_level_module_budget.py验证通过。
关键代码讲解
ACPStdioAdapter(loopx/chat/acp.py#L42-L593):负责通过 stdio JSON-RPC 2.0 启动、恢复和关闭本地/远程 ACP Agent 会话并流式转发事件。迁移后仅将其顶部对loopx.chat与loopx.chat_agent的相对导入从单点改为from ..chat import ...与from ..chat_agent import ...,内部超时控制、权限请求拒绝与优雅退出逻辑一字未改。AgentEndpointRegistry(loopx/chat/endpoints.py#L221-L274):管理 owner-local 自定义 ACP 端点的endpoints.json读写(0600原子写入、文件锁、RESERVED_AGENT_IDS防覆盖保护)。迁入后将内部相对导入更新为from ..chat_store import utc_now、from ..file_lock import ...、from ..kiro_cli_goal_mode import KIRO_CLI_CHAT_AGENT_ID,同时保持ChatRuntimeController(loopx/chat_runtime.py#L49,L280,L330)与handle_chat_endpoint_command(loopx/cli_commands/support_control_chat_endpoint.py#L8,L49)的单一所有权不变。ClaudeCodeAdapter与codex_model_options(loopx/chat/providers.py#L25-L60,L154-L330):分别封装 Codex 模型目录探测、Claude Code 只读 CLI 会话以及 Anthropic/OpenAI 直连只读工具循环。迁入后将from .chat/from .chat_agent改为from ..chat/from ..chat_agent,同步在loopx/chat/session_open.py#L51,L63使用同包相对导入from .acp import ACPStdioAdapter与from .providers import ClaudeCodeAdapter, direct_model_from_environment。observed_model_settings与inspect_agent_model_options(loopx/capabilities/native_chat/model_settings.py#L100-L239):分别在模型选项查询、会话模型配置以及会话恢复校验时懒导入from ...chat import providers与from ...chat.acp import ACPStdioAdapter。同时tests/test_chat_agent_model_http.py与tests/test_chat_reasoning_selection.py中的monkeypatch.setattr("loopx.chat_providers.codex_model_options", ...)字符串路径也全部同步为"loopx.chat.providers.codex_model_options"。
对主干的风险 / Risks
- 全仓残留引用与负向/反事实检查(PASS):在独立干净工作树中(重装可编辑
loopx确认loopx.__file__与loopx.chat.__path__指向当前 PR 检出目录后),对全仓执行rg -n "\bchat_(acp|endpoints|providers)\b"验证零残留旧路径调用或字符串 monkeypatch;Python 负向检查确认importlib.util.find_spec对loopx.chat_acp、loopx.chat_endpoints与loopx.chat_providers均返回None;AgentEndpointRegistry实测拒绝保留 ID"codex"并允许正常端点写入/列表,loopx.cli chat-endpoint list返回空列表 JSON(ok: true)。 - 验证矩阵与覆盖边界(PASS):
- 架构与 Chat 定向
pytest(21 个文件):1120 passed, 6 skipped in 532.97s(6 项skipped为tests/control_plane/test_installed_core_context.py需外部LOOPX_CORE_TEST_PYTHON环境的用例)。 - 本地真实入口 smoke:
examples/loopx-chat-acp-adapter-smoke.py(ok)、examples/loopx-chat-provider-adapters-smoke.py(ok)、与构建仪表盘资源后的examples/loopx-chat-server-smoke.py(ok)全部通过;examples/personal-workspace-browser/first-goal-agent-unavailable.mjs通过node --check。 - 静态与公开边界检查:
ruff check(22 个.py文件全通过)、mypy(pyproject.toml17 个 strict 文件全通过)、scripts/check_rfc_bilingual.py --base origin/main --head HEAD通过、git diff --check通过、loopx check(25 个文件errors=0)通过、canary premerge在隔离HOME下 6/6 直接检查 + 10/10 目录 canary + 8/8 风险 smoke + 1/1 边界检查全部 PASS。
- 架构与 Chat 定向
- 并发批次与分支推进观察(非阻断):审查期间
origin/main已合入 PR#9193推进至202d7bdb05,致使canary premerge相对最新origin/main的scope_fingerprint未命中作者先前在db76a91f0c记录的 CQR(cqr_62b712366d71f399f220),但#9193与本 PR 零文件重叠,GitHub 状态仍为MERGEABLE(BEHIND)。另top_level_module_budget.json的baseline_commit记录为00f47ed364(db76a91f0c^1,顶层模块同样为 122 个),与并行的 PR #9179 合入其中之一后,后合入方只需按合并后计数(119 -> 116)与test_chat_internal_module_layout.py/chat_runtime.py重演单行 rebase 即可。
我的整体评价 / Verdict
本 PR 为 justified_increment:严格遵循 #5072 / monorepo-distribution-split-v0.md 的 M1 与 I3 规则,在不改变任何运行时或对外契约的前提下完成 3 个内部 Chat 叶子模块归位与预算棘轮下调。
- Long-horizon(
improved):loopx/顶层模块从 122 稳定降至 119 且禁止顶层兼容 shim 回流,降低了后续分包重构与调用方定位的长期维护成本。 - User experience(
preserved)与 Visual review(not_applicable):本次仅调整内部 Python 模块布局、测试导入与文档引用,不涉及前端 UI 组件或视觉呈现改动(已核对loopx/chat/acp.py、loopx/chat/endpoints.py、loopx/chat/providers.py与examples/personal-workspace-browser/first-goal-agent-unavailable.mjs,unverified_scope:none)。 - 语义词表与兼容决策:未新增、扩展或改变任何状态枚举或协议字段(
semantic_alignment:not_applicable);compatibility_assessment为not_applicable(纯内部模块,无公开重导出);observable_semantics与default_off_isolation均验证等价/不适用(equivalent/not_applicable)。 - Exact-head freshness:复核远端
HEAD仍为993ecae82ddf0b19185e8e99e4468a1788e181c4(OPEN、MERGEABLE、wait_for_ci: false),全部本地定向测试、smoke 与静态边界检查均已在该精确 head 独立跑通。
English verdict: APPROVE at exact head 993ecae (published as COMMENTED review because PR #9196 is author-owned; 3 internal Chat leaf modules moved cleanly to loopx/chat/{acp,endpoints,providers}.py with zero shims, all callers/monkeypatches/smokes updated, top_level_module_budget ratcheted 122 -> 119, 1120 pytest cases + 3 chat smokes + ruff + mypy + canary premerge 19/19 PASS).
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
维护者正在按 M1 迁移 Chat 内部模块,每批还要通过顶层实际数量门禁。 #5072 将可兼容迁移和精确模块计数绑定在同一 PR,避免为降低表面数字留出新增长空间。 当前 main 有 121 个顶层 Python 模块,合入本提案的三个搬迁后实际为 118。临时整合树只选择主干的 121 或提案的 119 作为预算时,原精确计数测试均失败。把预算改为实测 118 后,预算与模块布局合计 9 项通过。 这批把 ACP、端点登记和 provider 适配迁进 loopx.chat,更新内建调用点。源分支固定的 119 对应旧分叉。 本轮只核验 M1 的三个模块和兼容边界。剩余 Chat 模块与发行分包仍由 #5072 跟踪。
改动思路 / Approach
保留原 Chat 架构与接口责任,更新相对导入和已有启动路径。 内部模块从同一分发包重新归位。公开命令、配置和效果所有者仍沿现有入口。 整合时只需在现有精确计数 owner 设置实际数值,现有生产模块的组合可保留。
具体改动 / Changes
逐项检查当前头 993ecae 和 merge base db76a91,25 个文件,+50/-39。主干 a6ffb3b 的合并预演只在模块预算 fixture 有内容冲突。其余生产文件由 Git 自动整合。我分别用两侧 fixture 跑了同一项门禁,再在临时树按实测值对照。 评审依据为 a6ffb3b。 目标规范
- m1-chat-leaf-relocation · Move internal ACP, endpoint, and provider modules into the existing Chat package.
- i3-active-callers · Preserve established public interfaces and update existing internal callers with no stale imports.
- current-main-module-budget · Pin the real merged top-level count after the three moves.
关键代码讲解
对主干的风险 / Risks
[P2] 当前主干整合的精确模块预算应为 118。 在当前 main 上重基并把预算更新到实际的 118,保留现有 allowlist。用同一提交重跑准确计数、内部导入和包边界。 选择任一冲突侧都会使 mandatory architecture gate 失败。无需扩大迁移范围即可恢复。
分叉基线有 122 个顶层模块,提案准确头有 119。该头通过 110 项定向 Python 测试及本地 quick premerge,覆盖无旧 shim 的布局、ACP 启动、端点和聊天配置。 隔离 Core wheel 的命令帮助在无 Node 的 PATH 可启动。 重建标准 wheel 后,三个新模块均由已安装包加载,ACP stdio 和 provider fixture 实跑通过。 整合树使用主干值和提案值时分别为 1 项失败、5 项通过。按同一生产树实际数量收紧后,预算和布局 9 项通过。 临时整合只用于验证。远端 PR 分支仍含内容冲突。
我的整体评价 / Verdict
请求修改。保留原 Chat 架构与接口责任,更新相对导入和已有启动路径。 内部模块从同一分发包重新归位。公开命令、配置和效果所有者仍沿现有入口。 搬迁可在旧分叉基线上通过,当前分支的规范预算和主干组合仍待提交。 请在新基线记录整合后的精确预算,并在不改动 MCP、provider 或 Chat 权限的前提下复验同一头。
English verdict: REQUEST_CHANGES at 993ecae. The exact relocation passes focused Chat tests. Current main plus these moves contains 118 top-level modules. The architecture gate fails with either side's conflicting budget and passes when the integrated budget is set to the measured count.
| "baseline_commit": "41ea75e89892ed88d0ae543e97e31aad0a181c47", | ||
| "max_top_level_modules": 122, | ||
| "baseline_commit": "00f47ed364819d9866846ff200ef56fa604f0cdf", | ||
| "max_top_level_modules": 119, |
There was a problem hiding this comment.
[P2] 当前主干整合的精确模块预算应为 118。当前 main 有 121 个顶层 Python 模块,合入本提案的三个搬迁后实际为 118。临时整合树只选择主干的 121 或提案的 119 作为预算时,原精确计数测试均失败。把预算改为实测 118 后,预算与模块布局合计 9 项通过。 在当前 main 上重基并把预算更新到实际的 118,保留现有 allowlist。用同一提交重跑准确计数、内部导入和包边界。
Goal And Delivered Outcome
docs/architecture/rfcs/monorepo-distribution-split-v0.md(Milestone M1, Invariant I3, and Section 9 top-level module budget ratchet; related to RFC: split LoopX distributions inside the monorepo (loopx-core / loopx-workspace / capability packages) and pin top-level module growth #5072).loopx/chat_acp.py,loopx/chat_endpoints.py,loopx/chat_providers.py) still sat at the package top level (122top-level modules) instead of co-locating underloopx/chat/.(Note:
loopx/chat_action_store.pywas intentionally skipped in this batch becausepackages/loopx-core/prepare.pyandtests/control_plane/test_installed_core_context.pycurrently assert the top-levelloopx.chat_action_storedistribution boundary; swapped cleanly toloopx/chat_acp.pywith zero overlap against PR refactor(chat): colocate leaf chat helpers under loopx.chat and ratchet module budget (#5072) #9179.)loopx/held122top-level*.pymodules (tests/architecture/top_level_module_budget.jsonpinned122).loopx/chat/(acp.py,endpoints.py,providers.py) viagit mvwith zero top-level compatibility shims, updated all internal callers, monkeypatches, tests, smokes, andkiro_cli_goal_modedocs/comments, added no-shim assertions intests/test_chat_internal_module_layout.py, and ratchetedmax_top_level_modulesdown to119(baseline_commit00f47ed364819d9866846ff200ef56fa604f0cdf). Proven bytests/architecture/test_top_level_module_budget.py,tests/test_chat_internal_module_layout.py, targeted chat/architecture pytest (821 passed), andcanary premerge.main.Author Declaration
Implemented against
docs/architecture/rfcs/monorepo-distribution-split-v0.md(M1,I3, Section 9) atdb76a91f0cc1afb8b10505a94b0a44cf017aaa69loopx/chat/loopx/chat/acp.py,loopx/chat/endpoints.py,loopx/chat/providers.pypytest -q --no-cov tests/test_chat_internal_module_layout.pyloopx/chat/session_open.py,loopx/capabilities/native_chat/model_settings.py,loopx/chat_runtime.py,loopx/cli_commands/support_control_chat_endpoint.py,loopx/kiro_cli_goal_mode/*,tests/*,examples/*rg -n "chat_(acp|endpoints|providers)"+tests/test_chat_internal_module_layout.pytests/architecture/top_level_module_budget.json(122→119)pytest -q --no-cov tests/architecture/test_top_level_module_budget.pyls -1 loopx/*.py | wc -l==119, verified zero dangling old-module imports/monkeypatches across code/tests/examples/docs viarg, verified bilingual RFC check, ranruff,mypy, affected chat smokes (acp-adapter,provider-adapters,chat-server), browser smoke syntax check (node --check), targeted pytest (821 passed+9 passedbudget/layout re-run),loopx check(0errors), Goal-boundchange-quality(cqr_62b712366d71f399f220), andcanary premerge(19/19selected checks passed,0failures).Scope And Continuation
122→119). Remaining top-levelloopx/chat_*.pymodules and M1–M5 distribution split work stay open under RFC: split LoopX distributions inside the monorepo (loopx-core / loopx-workspace / capability packages) and pin top-level module growth #5072 (and parallel PR refactor(chat): colocate leaf chat helpers under loopx.chat and ratchet module budget (#5072) #9179 moveschat_attachments,chat_dsh,chat_operator_provider_api).tests/test_chat_internal_module_layout.py; no follow-up slice invented here.Validation
993ecae82ddf0b19185e8e99e4468a1788e181c4finishedsynthetic,public_fixtureunitpassedpytest -q --no-cov tests/architecture/test_top_level_module_budget.py tests/architecture/test_control_plane_import_boundaries.py tests/architecture/test_package_kernel_import_ratchet.py tests/test_chat_internal_module_layout.py tests/test_atomic_write_modes.py tests/test_chat_acp_startup_timeout.py tests/test_chat_agent_model_http.py tests/test_chat_codex_defaults.py tests/test_chat_endpoint_readiness.py tests/test_chat_goal_workspace_selection.py tests/test_chat_long_running.py tests/test_chat_path_redaction.py tests/test_chat_reasoning_selection.py tests/test_kiro_cli_host_surface.py tests/test_chat_machine_configuration_api.py tests/test_chat_startup_isolation.py tests/test_chat_agent.py→821 passed in 82.98s; re-rantests/architecture/test_top_level_module_budget.py tests/test_chat_internal_module_layout.pyafterbaseline_commitupdate →9 passed in 0.32sstaticpassedruff checkon all 22 changed.pyfiles (All checks passed!),python -m mypy(Success: no issues found in 17 source files),python scripts/check_rfc_bilingual.py --base origin/main --head HEAD(RFC bilingual diff check passed.),node --check examples/personal-workspace-browser/first-goal-agent-unavailable.mjs(exit 0),loopx check --scan-path ...(ok: true,errors: 0,39files clean)real_entrypointpassedpython examples/loopx-chat-acp-adapter-smoke.py(ok),python examples/loopx-chat-provider-adapters-smoke.py(ok),python examples/loopx-chat-server-smoke.py(ok, built local chat bundle),loopx canary premerge --from-git-diff --git-diff-base origin/main(ok: true,direct_checks: 6/6,selected_checks: 19/19,failure_count: 0,change_qualityreceiptcqr_62b712366d71f399f220valid)chat_acp,chat_endpoints, orchat_providerswere checked and exercised;examples/personal-workspace-browser/first-goal-agent-unavailable.mjswas syntax-checked (node --check) rather than executed end-to-end in Playwright (full-repo pytest and remote CI were not run).Frontend / Visual Evidence
nonenoneType of Change
LoopX Area
Technical Direction
docs/architecture/rfcs/monorepo-distribution-split-v0.md(M1,I3, Section 9)Shared-authority RFC fixture impact
N/A
Boundary Checklist
.loopx/,.codex/goals/, and liveACTIVE_GOAL_STATE.md).python3 scripts/check_rfc_bilingual.py --base origin/main --head HEADpasses, or no paired RFC changed.none.Signed-off-bytrailer (git commit -s).